//
//  LSCompetitionVController.m
//  LookScore
//
//  Created by wr on 2017/12/5.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSCompetitionVController.h"
#import "LSLiveCompetitionViewController.h"
#import "LSCustomHeaderView.h"
#import "LSCompetitionActionCell.h"
#import "LSCompetitionModel.h"
#import "LSTimeSelectView.h"
#import "ZJScrollPageView.h"
#import "LSCompetitionSubViewController.h"

@interface LSCompetitionVController ()<ZJScrollPageViewDelegate>

@property (nonatomic, strong) ZJScrollPageView *scrollPageView;
@property(strong, nonatomic)NSArray<NSString *> *titles;
@property (nonatomic, assign) NSInteger screeningThePage;
@property (nonatomic, strong) NSMutableArray * childArray;

@end

@implementation LSCompetitionVController{
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
    
}
-(NSMutableArray *)childArray{
    if (!_childArray) {
        _childArray = @[].mutableCopy;
    }
    return _childArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.title=@"赛事";
    self.view.backgroundColor=LSBackGroundColor;
  
    self.imageArray=@[@"NavFiltrate",@"NavSetting",@"NavDataBank"];

    [self initPagerView];
   
    self.modelArray = @[].mutableCopy;
//    self.childArray = [self setChildVc];
}

#pragma mark 🔥 UI
-(void)initPagerView{
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
    
    style.scrollLineColor=LSNavMainColor;
    
    style.segmentHeight=35;
    
    style.autoAdjustTitlesWidth=YES;
    
    style.normalTitleColor=[UIColor colorWithRed:255.f/255.f green:255.f/255.f blue:255.f/255.f alpha:1];
    
    style.selectedTitleColor=LSNavTitlenColor;
    
    style.scrollLineColor=LSNavTitlenColor;
    
    self.titles = @[@"关注", @"即时",@"完场", @"赛程"];
    // 初始化
    _scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,self.view.bounds.size.height) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
    [_scrollPageView setSelectedIndex:1 animated:NO];
    _scrollPageView.segmentView.backgroundColor=LSNavMainColor;
    [self.view addSubview:_scrollPageView];
}
#pragma mark -- 父类的方法
- (void)changCompetitionLeagueNameArray:(NSMutableArray *)leagueNameArray withZouNameArray:(NSMutableArray *)zouNameArray withType:(NSInteger)type{
    NSMutableArray * array = self.childArray.mutableCopy;
    LSCompetitionSubViewController * subVC = (LSCompetitionSubViewController *)array[_screeningThePage];
    subVC.optionType = type;
    subVC.modelArray = self.superComtitionArray;
    subVC.screeningThePage = _screeningThePage;
    subVC.leagueNameArray = leagueNameArray;
    subVC.zouLeagueNamaArray = zouNameArray;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
    if (!childVc) {
        LSCompetitionSubViewController *IMVC;
        for (NSInteger i = 0; i< 4; i++) {
            IMVC = [[LSCompetitionSubViewController alloc] init];
            
            KWeakSelf(self);
            IMVC.block = ^(NSMutableArray *leaArray,NSMutableArray *zouLeaArray,NSMutableArray *modelArray,NSInteger type) {
                weakself.leaArray = leaArray;
                weakself.zouLeaArray = zouLeaArray;
                weakself.superComtitionArray = modelArray.mutableCopy;
                _screeningThePage = type;
                if (type == 2 || type == 1) {
                    self.navigationItem.leftBarButtonItem.customView.hidden = NO;
                }else{
                    
                    self.navigationItem.leftBarButtonItem.customView.hidden = YES;
                }
            };
            
            IMVC.badgeNumberBlock = ^(NSInteger badgeNumber) {
                [_scrollPageView showBadgeViewWith:badgeNumber];
            };
            
            [self.childArray addObject:IMVC];
        }
        
        
        childVc = self.childArray[index];
    }
    return childVc;
}

- (NSInteger)numberOfChildViewControllers {
   return self.titles.count;
}

- (BOOL)shouldAutomaticallyForwardAppearanceMethods {
    return NO;
}
- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllDidAppear:(UIViewController *)childViewController forIndex:(NSInteger)index{
    
//    IMVC.screeningThePage = index;

}

- (void)scrollPageController:(UIViewController *)scrollPageController childViewControllWillAppear:(UIViewController *)childViewController forIndex:(NSInteger)index{
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
